package com.first.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.first.common.pojo.EduChapter;
import com.first.common.pojo.TbPlayHistory;
import com.first.common.vo.Result;
import com.first.order.service.ChapterService;
import com.first.order.service.TbPlayHistoryService;
import com.first.order.vo.InsertChapterWithCourseIdVo;
import com.first.order.vo.EduChapterVo;
import com.first.order.vo.TbPlayHistoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: first-project
 * @description:
 * @author: 路志欣
 * @create: 2023-06-05 17:35
 **/
@RestController
@RequestMapping("order")
@Api(tags = "学习记录")
public class TbPlayHistoryController {
    @Autowired
    private TbPlayHistoryService tbPlayHistoryService;
    @Autowired
    private ChapterService chapterService;

    @ApiOperation(value = "学习记录")
    @PostMapping("play-history/queryPlayHistoryBy/{currentPage}/{pageCount}/{memberId}")
    public Result queryPlayHistoryBy(@PathVariable Integer currentPage, @PathVariable Integer pageCount, @PathVariable String memberId, @RequestBody TbPlayHistoryVo tbPlayHistoryVo) {
        IPage<TbPlayHistory> byId = tbPlayHistoryService.findById(currentPage, pageCount, memberId);
        return Result.success(byId);
    }

    @ApiOperation(value = "根据课程id查询章节和课时信息")
    @PostMapping("chapter/findChapterById/{id}")
    public Result findChapterById(@PathVariable String id) {
        List<EduChapter> list = chapterService.findChapterById(id);
        return Result.success(list);
    }

    @ApiOperation(value = "修改与添加课程章节内容")
    @PostMapping("chapter/insertChapterWithCourseId")
    public Result insertChapterWithCourseId(@RequestBody InsertChapterWithCourseIdVo chapterWithCourseIdVo) {
        Integer insert = chapterService.insertChapterWithCourseId(chapterWithCourseIdVo);
        if (insert == 1){
            return  Result.success(chapterService.findChapterById(chapterWithCourseIdVo.getCourseId()));
        }
            return Result.fail("添加课程章节内容失败");
    }

    @ApiOperation(value = "添加学习记录")
    @PostMapping("play-history/insertPlayHistoryByCourseId/{HuiYuanId}/{vedeoId}")
    public Result insertPlayHistoryByCourseId(@PathVariable String HuiYuanId, @PathVariable String vedeoId) {
        Integer integer = tbPlayHistoryService.insertPlayHistoryByCourseId(HuiYuanId, vedeoId);
        return Result.success(integer);
    }
    @ApiOperation(value = "根据课程id修改课时信息")
    @PostMapping("/ChapterWithCourseId")
    public Result ChapterWithCourseId(@RequestBody InsertChapterWithCourseIdVo insertChapterWithCourseIdVo) {
       /* System.out.println(eduChapterVo);*/
        Integer integer = chapterService.insertChapterWithCourseId(insertChapterWithCourseIdVo);
        if (integer == 1){
            return  Result.success(chapterService.findChapterById(insertChapterWithCourseIdVo.getCourseId()));
        }
        return Result.fail("修改课程章节内容失败");
    }
    @ApiOperation(value = "根据课程id删除课时信息")
    @PostMapping("chapter/deleteChapterWithCourseId")
    public Result deleteChapterWithCourseId(@RequestBody EduChapterVo eduChapterVo) {
        /*System.out.println(eduChapterVo);*/
        Integer integer = chapterService.deleteChapterWithCourseId(eduChapterVo);
        return Result.success(integer);
    }
}
